﻿using Mes.Pendant.ProcurementWarehousings;
using Mes.Pendant.ProcurementWarehousings.Dto;
using Mes.Pendant.SupplierInterface;
using Mes.Pendant.SupplierInterface.SupplierDto;
using Mes.Pendant.SupplierServices;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Mes.Pendant.Web.Controllers
{
    public class ProcurementWarehousingController : Controller
    {
        private readonly IProcurementWarehousingService _procurementWarehousingService;

        public ProcurementWarehousingController(IProcurementWarehousingService procurementWarehousingService)
        {
            _procurementWarehousingService = procurementWarehousingService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult ProcurementWarehousingList()
        {
            return View();
        }

        public IActionResult Add()
        {
            return View();
        }

        public IActionResult Update(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public async Task<JsonResult> GetProcurementWarehousingList(string? lbounListCode, string? lbounListName, int page = 1, int limit = 10)
        {
            var result = await _procurementWarehousingService.GetProcurementWarehousingList(lbounListCode, lbounListName, page, limit);
            return Json(new { data = result.Queryable, count = result.RowCount, code = 0 });
        }

        public async Task<int> AddProcurementWarehousing(ProcurementWarehousingDto procurementWarehousingDto)
        {
            var result = await _procurementWarehousingService.AddProcurementWarehousing(procurementWarehousingDto);
            return result;
        }
        public async Task<int> DeleteProcurementWarehousing(int id)
        {
            var result = await _procurementWarehousingService.DeleteProcurementWarehousing(id);
            return result;
        }

        public async Task<JsonResult> GetProcurementWarehousingInfo(int id)
        {
            var list = _procurementWarehousingService.GetProcurementWarehousingInfo(id);
            return Json(new { data = list.Result });

        }

        public async Task<int> UpdateProcurementWarehousing(ProcurementWarehousingDto procurementWarehousingDto)
        {
            var result = await _procurementWarehousingService.UpdateProcurementWarehousing(procurementWarehousingDto);
            return result;
        }

        public async Task<JsonResult> Getsuppernames()
        {
            var result = await _procurementWarehousingService.Getsuppernames();
            return Json(new { data = result });
        }
    }
}
